import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
	
	{
	  path: "/apiTester",
	  component: () => import("@/views/itester/index.vue"),
	  meta: { hidden: true },
	},
	{
	  path: "/preview",
	  component: () => import("@/views/preview/index.vue"),
	  meta: { hidden: true },
	},
	
	{
	  path: "/editor",
	  component: () => import("@/views/editor/index.vue"),
	  meta: { hidden: true },
	},
	
  {
    path: "/",
    redirect: "/dashboard",
	  component: Layout,
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard",
        meta: { title: "工作台", icon: "dashboard", affix: true },
      },
    ],
  }, 
	{
	  path: "/project",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "project",
	      component: () => import("@/views/project/index.vue"),
	      name: "project",
	      meta: { title: "底板管理", icon: "template" },
	    },
	  ],
	},
	{
	  path: "/scene",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "scene",
	      component: () => import("@/views/scene/index.vue"),
	      name: "scene",
	      meta: { title: "场景管理", icon: "scene" },
	    },
	  ],
	},
	{
	  path: "/asset",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "asset",
	      component: () => import("@/views/asset/index.vue"),
	      name: "asset",
	      meta: { title: "资产管理", icon: "asset" },
	    },
	  ],
	},
	{
	  path: "/product",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "product",
	      component: () => import("@/views/product/index.vue"),
	      name: "product",
	      meta: { title: "组件管理", icon: "assembly" },
	    },
	  ],
	},
	{
	  path: "/agent",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "agent",
	      component: () => import("@/views/agent/index.vue"),
	      name: "agent",
	      meta: { title: "渲染服务", icon: "render" },
	    },
	  ],
	},
	{
	  path: "/system",
	  component: Layout,
	  redirect: "/user",
	  children: [
	    {
	      path: "user",
	      component: () => import("@/views/system/user/index.vue"),
	      name: "user",
	      meta: { title: "用户管理", icon: "user" },
	    }
	  ],
	},
	{
	  path: "/system",
	  component: Layout,
	  redirect: "/log",
	  children: [
	    {
	      path: "log",
	      component: () => import("@/views/system/log/index.vue"),
	      name: "log",
	      meta: { title: "日志管理", icon: "log" },
	    }
	  ],
	},
	{
	  path: "/apiForUE",
	  component: Layout,
	  redirect: "/",
	  children: [
	    {
	      path: "apiForUE",
	      component: () => import("@/views/apiForUE/index.vue"),
	      name: "apiForUE",
	      meta: { title: "接口管理", icon: "api" },
	    }
	  ],
	},
];
/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
